package com.huazi.eduservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.huazi.commonutils.CommentResult;
import com.huazi.eduservice.EduApplication;
import com.huazi.eduservice.entity.EduCourse;
import com.huazi.eduservice.entity.EduTeacher;
import com.huazi.eduservice.service.EduCourseService;
import com.huazi.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author shkstart
 * @create 2021-03-25 15:11
 */
@CrossOrigin
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {
    @Autowired
    EduCourseService courseService;

    @Autowired
    EduTeacherService teacherService;
    @GetMapping("getIndex")
    public CommentResult getIndex(){
        //前8门热门课程
        List<EduCourse> courses = courseService.list(
                new QueryWrapper<EduCourse>()
                        .orderByDesc("id")
                        .last("limit 8"));

        //前4个热门讲师
        List<EduTeacher> teachers = teacherService.list(
                new QueryWrapper<EduTeacher>()
                        .orderByDesc("id")
                        .last("limit 4"));

        return CommentResult.getOK().data("courses",courses).data("teachers",teachers);

    }
}
